package com.pandacc.common;

/**
 * 打印byte数组
 * @author Administrator
 *
 */
public class ByteUtils {

	public static void dumpMemory(String str){
		if (str == null) {
			return;
		}
		byte[] buf = str.getBytes();
        int j = 0;
        int k = 0;
        int i = 0;
        byte c ;
        int WID = 16;
        System.out.println(str + "--" + buf.length);
        while(j*WID < buf.length){
            System.out.printf(" %04X: ", j*WID);
            for(i = 0; i < WID; i++){
                if((i + j * WID)>=buf.length) {break;}
                c = buf[i + j * WID];
                System.out.printf("%02X ",c);
                if((i+1) % 8 == 0) {System.out.print(" ");}
            }
            for(k=i; k<WID; k++){
                System.out.printf(" ");
                if((k+1) % 8 == 0) {System.out.printf(" ");}
            }
            System.out.printf(" ");

            for(i=0; i<WID; i++){
                if((i+j*WID) >= buf.length) {break;}
                c = buf[i+j*WID];
                if(c >= 0x30 && c <= 0x7a){
                    System.out.printf("%c",c);
                }else{
                    System.out.printf("%c",'.');
                }
            }
            System.out.printf("\n");
            j++;
        }
    }
}
